﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Blog.Data;
using Blog.Models;
using BlogModel;
using BlogModel.DAL;

namespace Blog.Controllers
{
    public class PostController : Controller
    {
        //
        // GET: /Post/
        public ActionResult Index(int id)
        {
            var posts = PostRepository.GetPostsByUserId(id);
            if (posts != null)
                return View(posts);
            else
                return HttpNotFound();

        }
        

        public ActionResult FullDetails(int id)
        {

            var post = PostRepository.GetPostByPostId(id);
            post.Comment = new CommentModel();
            if (post != null)
                return View(post);
            else
                return HttpNotFound();


            //PostModel postModel = new PostModel();
            //postModel.Users = UserDB.GetUserOnUserId(id);
            //postModel.Blogs = BlogDB.GetBlogOnUserId(id);
            ////postModel.Posts = PostDB.GetPostsByUserId(id);
            //postModel.Post = PostDB.GetPostByPostId(id);
            //postModel.BlogRolls = BlogRollDB.GetBlogRollsOnUserId(id);

            //postModel.Comment=new CommentModel();
            //if (postModel != null)
            //    return View(postModel);
            //else
            //    return HttpNotFound();



           
        }


        public ActionResult CreateComment(CommentModel comment)
        {
            if(ModelState.IsValid)
            { 
                comment.CreationDate = DateTime.UtcNow;
                CommentRepository.AddComment(comment);
                return RedirectToAction("FullDetails", new{id=comment.PostId});
            }

            return RedirectToAction("FullDetails", new { id = comment.PostId });
        }
	}
}